<template>
  <div>
    <div class="wrap">
      <div class="item" :key="index" v-for="(item, index) in specialList"  @click="topicDetail(item.id)">
        <img :src="item.scene_pic_url">
        <div class="text">
          <h1>{{item.title}}</h1>
          <p>{{item.subtitle}}</p>
          <span>{{item.price_info}}元起</span>
        </div>
        <v-split></v-split>
      </div>
    </div>
  </div>
</template>

<script>
import {get} from '@/utils'
import vSplit from '@/components/split'

export default {
  data () {
    return {
      specialList: [],
      page: 0,
      pageSize: 5,
      more: false
    }
  },
  methods: {
    async getData (init) {
      if (init) {
        this.page = 0
      } else {
        this.page = this.page + 1
      }
      const res = await get('/weapp/special', {
        page: this.page,
        pageSize: this.pageSize
      })
      if (res.specialList.length === this.pageSize) { // 判断是否还有数据  没有则下拉不发请求
        this.more = true
      } else {
        this.more = false
      }
      this.specialList = this.specialList.concat(res.specialList)
      wx.hideLoading()
    },
    topicDetail (id) {
      wx.navigateTo({
        url: `/pages/topicDetail/main?id=${id}`
      })
    }
  },
  mounted () {
    wx.showLoading({
      title: '加载中'
    })
    this.getData(true)
  },
  onPullDownRefresh () {
    // 下拉刷新
    console.log('下拉刷新')
  },
  onReachBottom () {
    if (this.more) {
      wx.showLoading({
        title: '加载中'
      })
      this.getData()
      wx.stopPullDownRefresh()
    }
  },
  components: {
    vSplit
  }
}
</script>

<style lang="less" scoped>
.item{
  background: #fff;
  img{
    width: 100%;
  }
  .text{
    text-align: center;
    padding-bottom: 20rpx;
    h1{
      font-size: 32rpx;
      height: 50rpx;
      line-height: 50rpx;
      font-weight: 700;
    }
    p{
      line-height: 40rpx;
      font-size: 26rpx;
      color: #b7b7b7;
      
    }
    span{
      color: #b4282d;
      font-size: 30rpx;
    }
  }
  .hint{
    color: #000;
    font-size: 28rpx;
  }
}
</style>
